package com.rgc.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.rgc.dao.LocalidadDao;
import com.rgc.domain.Comuna;

@Controller
@RequestMapping(value = "/listado")
public class ControladorListados {
	ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
	 protected LocalidadDao localidadDao = (LocalidadDao) context.getBean("localidadDao");
	
	@RequestMapping(value = "/comuna",method = {RequestMethod.GET,RequestMethod.POST},headers = "Accept=application/json")
	@ResponseBody
	public String geComuna
    	(HttpSession session,HttpServletRequest request,@RequestParam(value="idregion",required=true) String idregion ) {

	  
	  List<Comuna> comunas= localidadDao.getComunalist(idregion);
	  String salida="<option value='0'>--Comuna--</option>";
      for(Comuna comuna: comunas){
    	  salida+="<option value='"+comuna.getIdcomuna()+"'>"+comuna.getNombre()+"</option>";
      }
      System.out.println(salida);
      
      return salida;
	}

}
